Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shrink Statement. #55346

Merged
merged 1 commit into from
Oct 26, 2018
Merged

Shrink Statement. #55346

merged 1 commit into from
Oct 26, 2018

Conversation

nnethercote
Copy link
Contributor

This commit reduces the size of Statement from 80 bytes to 56 bytes on
64-bit platforms, by boxing the AscribeUserType variant of
StatementKind.

This change reduces instruction counts on most benchmarks by 1--3%.

@rust-highfive
Copy link
Collaborator

r? @pnkfelix

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 25, 2018
@nnethercote
Copy link
Contributor Author

Here are the instruction count improvements that exceed 1%.

style-servo-debug
	avg: -2.1%	min: -3.2%	max: 0.4%
webrender-debug
	avg: -1.4%	min: -2.9%	max: -0.1%
regression-31157-debug
	avg: -1.6%	min: -2.7%	max: -0.4%
issue-46449-debug
	avg: -2.4%	min: -2.7%	max: -1.2%
cargo-debug
	avg: -1.8%	min: -2.4%	max: -0.1%
piston-image-debug
	avg: -1.2%	min: -2.3%	max: -0.2%
regex-debug
	avg: -1.4%	min: -2.3%	max: -0.1%
crates.io-debug
	avg: -1.3%	min: -2.3%	max: -0.1%
syn-debug
	avg: -1.3%	min: -2.2%	max: -0.1%
clap-rs-debug
	avg: -1.4%	min: -2.2%	max: 0.2%
helloworld-check
	avg: -1.9%	min: -2.0%	max: -1.7%
encoding-debug
	avg: -1.1%	min: -1.9%	max: -0.2%
deeply-nested-debug
	avg: -1.7%	min: -1.9%	max: -1.3%
sentry-cli-debug
	avg: -1.0%	min: -1.9%	max: -0.0%
unify-linearly-check
	avg: -1.3%	min: -1.8%	max: -0.9%
deeply-nested-check
	avg: -1.2%	min: -1.8%	max: -0.8%
ctfe-stress-debug
	avg: 0.2%?	min: -1.3%?	max: 1.7%?
tokio-webpush-simple-debug
	avg: -1.2%	min: -1.6%	max: -0.1%
ctfe-stress-check
	avg: -0.5%?	min: -1.6%?	max: 0.7%?
ripgrep-debug
	avg: -0.7%	min: -1.4%	max: 0.1%
ctfe-stress-opt
	avg: -0.9%?	min: -1.4%?	max: -0.4%?
coercions-debug
	avg: -0.5%?	min: -1.3%?	max: -0.0%?
issue-46449-check
	avg: -1.1%	min: -1.3%	max: -0.8%
deeply-nested-opt
	avg: -1.1%	min: -1.3%	max: -0.9%
webrender-opt
	avg: -0.9%	min: -1.2%	max: -0.1%
issue-46449-opt
	avg: -0.9%	min: -1.1%	max: -0.7%
clap-rs-opt
	avg: -0.7%	min: -1.1%	max: -0.1%
tokio-webpush-simple-opt
	avg: -0.7%	min: -1.0%	max: -0.2%
style-servo-opt
	avg: -0.7%	min: -1.0%	max: 0.1%
coercions-check
	avg: -0.4%?	min: -1.0%?	max: 0.0%?

@@ -1674,6 +1674,10 @@ impl<'tcx> Statement<'tcx> {
/// Changes a statement to a nop. This is both faster than deleting instructions and avoids
/// invalidating statement indices in `Location`s.
pub fn make_nop(&mut self) {
// `Statement` contributes significantly to peak memory usage. Make
// sure it doesn't get bigger.
debug_assert!(mem::size_of::<Statement<'_>>() <= 56usize);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you use a static assert instead:

#![feature(const_transmute, const_let)]

use std::mem;

#[allow(dead_code)]
const ASSERT_STATMENT_IS_56_BYTES: () = {
    unsafe { mem::transmute::<_, [u8; 56]>(Statement::Nop); }
    ()
};

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

librustc also has a static_assert! macro for this kind of pattern.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't know about that.

static_assert!(STATMENT_IS_AT_MOST_56_BYTES: std::mem::size_of::<Statement<'_>>() <= 56usize);

@nagisa
Copy link
Member

nagisa commented Oct 25, 2018

This is another instance of #54526.

It is nice to see there is an effort to add a test for this :)

r=me when debug_assert! becomes a static_assert! or a #[test].

@nnethercote
Copy link
Contributor Author

This is another instance of #54526.

Oh geez. I'd forgotten about that. Interestingly, that one didn't give an instruction count improvement, but this one does. Not sure why.

This commit reduces the size of `Statement` from 80 bytes to 56 bytes on
64-bit platforms, by boxing the `AscribeUserType` variant of
`StatementKind`.

This change reduces instruction counts on most benchmarks by 1--3%.
@nnethercote
Copy link
Contributor Author

I've updated to use static_assert!.

@Mark-Simulacrum
Copy link
Member

@bors r=nagisa

@bors
Copy link
Contributor

bors commented Oct 25, 2018

📌 Commit 38d9277 has been approved by nagisa

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 25, 2018
kennytm added a commit to kennytm/rust that referenced this pull request Oct 26, 2018
…=nagisa

Shrink `Statement`.

This commit reduces the size of `Statement` from 80 bytes to 56 bytes on
64-bit platforms, by boxing the `AscribeUserType` variant of
`StatementKind`.

This change reduces instruction counts on most benchmarks by 1--3%.
kennytm added a commit to kennytm/rust that referenced this pull request Oct 26, 2018
…=nagisa

Shrink `Statement`.

This commit reduces the size of `Statement` from 80 bytes to 56 bytes on
64-bit platforms, by boxing the `AscribeUserType` variant of
`StatementKind`.

This change reduces instruction counts on most benchmarks by 1--3%.
bors added a commit that referenced this pull request Oct 26, 2018
Rollup of 21 pull requests

Successful merges:

 - #54816 (Don't try to promote already promoted out temporaries)
 - #54824 (Cleanup rustdoc tests with `@!has` and `@!matches`)
 - #54921 (Add line numbers option to rustdoc)
 - #55167 (Add a "cheap" mode for `compute_missing_ctors`.)
 - #55258 (Fix Rustdoc ICE when checking blanket impls)
 - #55264 (Compile the libstd we distribute with -Ccodegen-unit=1)
 - #55271 (Unimplement ExactSizeIterator for MIR traversing iterators)
 - #55292 (Macro diagnostics tweaks)
 - #55298 (Point at macro definition when no rules expect token)
 - #55301 (List allowed tokens after macro fragments)
 - #55302 (Extend the impl_stable_hash_for! macro for miri.)
 - #55325 (Fix link to macros chapter)
 - #55343 (rustbuild: fix remap-debuginfo when building a release)
 - #55346 (Shrink `Statement`.)
 - #55358 (Remove redundant clone (2))
 - #55370 (Update mailmap for estebank)
 - #55375 (Typo fixes in configure_cmake comments)
 - #55378 (rustbuild: use configured linker to build boostrap)
 - #55379 (validity: assert that unions are non-empty)
 - #55383 (Use `SmallVec` for the queue in `coerce_unsized`.)
 - #55391 (bootstrap: clean up a few clippy findings)
@bors bors merged commit 38d9277 into rust-lang:master Oct 26, 2018
@nnethercote nnethercote deleted the shrink-StatementKind branch October 28, 2018 21:42
bors added a commit that referenced this pull request Oct 29, 2018
[beta]: Prepare the 1.31.0 beta release

* Update to Cargo's branched 1.31.0 branch
* Update the channel to `beta`

Rolled up beta-accepted PRs:

* #55362: Remove `cargo new --edition` from release notes.
* #55325: Fix link to macros chapter
* #55358: Remove redundant clone (2)
* #55346: Shrink `Statement`.
* #55274: Handle bindings in substructure of patterns with type ascriptions
* #55297: Partial implementation of uniform paths 2.0 to land before beta
* #55192: Fix ordering of nested modules in non-mod.rs mods
* #55185: path suggestions in Rust 2018 should point out the change in semantics
* #55423: back out bogus `Ok`-wrapping suggestion on `?` arm type mismatch

Note that **this does not update the bootstrap compiler** due to #55404
@@ -1674,6 +1674,10 @@ impl<'tcx> Statement<'tcx> {
/// Changes a statement to a nop. This is both faster than deleting instructions and avoids
/// invalidating statement indices in `Location`s.
pub fn make_nop(&mut self) {
// `Statement` contributes significantly to peak memory usage. Make
// sure it doesn't get bigger.
static_assert!(STATEMENT_IS_AT_MOST_56_BYTES: mem::size_of::<Statement<'_>>() <= 56);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this inside some random function, as opposed to, say, next to enum Statement?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't realize static_assert! was valid at the top level. I'll fix it in another PR, thanks for the tip.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants